import os
def process_file(input_filename, output_filename): 
    with open(input_filename, 'r', encoding='utf-8') as file: 
        lines = file.readlines() 
    
    processed_lines = []
    i = 0 
    while i < len(lines): 
        current_line = lines[i].strip() 

        # 检查当前行是否以 "**" 开头 
        if current_line.startswith('**'): 
            # 如果下一行不是空行，则在其后添加一个空行 
            if i + 1 < len(lines) and not lines[i+1].strip() == '': 
                processed_lines.append(current_line + '\n') 
                processed_lines.append('\n') # 添加一个空行 
                i += 1 # 跳过下一行，因为我们已经在当前行后添加了一个空行 
            else: 
                processed_lines.append(current_line + '\n') 
        else: processed_lines.append(current_line + '\n') 
        i += 1 
    # 写入新的文件 
    with open(output_filename, 'w', encoding='utf-8') as file: file.writelines(processed_lines) 

# 使用示例 
nopic = set([])
for line in os.popen("ls recipes/*.md").read().split("\n"):
    if "/" not in line: continue
    name = line.split("/")[1].split(".")[0]
    process_file(line.strip(), 'tmp/%s.md'%(name))
    cmd = "cp ./tmp/{0}.md ./recipes/{0}.md".format(name)
    print(cmd)
    os.system(cmd)
